﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Controls;

namespace 餐饮管理系统
{
    public partial class MainWindow : Window
    {
        private void loadSupplierSelected()
        {
            ListBoxItem supply = CenterListBox.SelectedItem as ListBoxItem;

            if (supply == null)
                return;

            string supplierName = supply.Content.ToString().Trim();
            string sql = "select * from SupplierTable where name = '" + supplierName + "'";
            SqlDataReader dataReader = databaseConnect.GetDataReader(sql);
            while (dataReader.Read())
            {
                SupplierBranchNameTextBox.Text = dataReader[0].ToString().Trim();
                SupplierBranchPhoneTextBox.Text = dataReader[1].ToString().Trim();
                SupplierBranchAddressTextBox.Text = dataReader[2].ToString().Trim();
                SupplyBranchRemarkTextBox.Text = dataReader[3].ToString().Trim();
            }
            dataReader.Close();
        }
        private void GongyingShouye_saveButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!HomePhoneRegex.IsMatch(SupplierBranchPhoneTextBox.Text))
            {
                MessageBox.Show("电话输入错误！");
                return;
            }
            string sql = "update SupplierTable "
                      + "set name = '" + SupplierBranchNameTextBox.Text + "',"
                      + "    phone = '" + SupplierBranchPhoneTextBox.Text + "',"
                      + "    address = '" + SupplierBranchAddressTextBox.Text + "',"
                      + "    remark = '" + SupplyBranchRemarkTextBox.Text + "' "
                      + "where name = '" + (CenterListBox.SelectedItem as ListBoxItem).Content.ToString().Trim() + "'";
            databaseConnect.ExecuteQuery(sql);
            loadSupplierSelected();
            loadCenterItems();
        }
    }
}

